package dapps.service.document;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.hibernate.EntityManager;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import dapps.dao.document.DocumentDao;
import dapps.entity.document.Document;
import dapps.service.ServiceException;

/**

 */
@Service
//默认将类中的所有函数纳入事务管理.
@Transactional
public class DocumentManager extends EntityManager<Document, Long> {
	@Autowired
	private DocumentDao documentDao;


	@Override
	protected DocumentDao getEntityDao() {
		return documentDao;
	}

	@Override
	public void delete(Long id) {

		//为演示异常处理及用户行为日志而抛出的异常.
		if (id == 1) {
			logger.warn("操作员{}尝试删除超级管理员用户", SpringSecurityUtils.getCurrentUserName());
			throw new ServiceException("不能删除超级管理员用户");
		}

		documentDao.delete(id);
	}




}
